package com.service;

import com.bean.Student;
import com.bean.Teacher;
import com.bean.User;
import com.dao.UserDao;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2016/9/10.
 */
@Service
public class UserService {
    @Autowired
    private UserDao userDao;

    public User getUser(User user) {
       List<User> users= userDao.getUserById(user);
       if (CollectionUtils.isNotEmpty(users)){
         return  users.get(0);
       }
       return null;
    }
    public List<User> getUserByUserName(String userName){
        List<User> user = userDao.getUserByUserName(userName);
        if (CollectionUtils.isNotEmpty(user)){
            return user;
    }
        return null;
    }
    public List<Student> getStudentByUserName(String userName){
        List<Student> user = userDao.getStudentByUserName(userName);
        if (CollectionUtils.isNotEmpty(user)){
            return user;
        }
        return null;
    }
    public List<Teacher> getTeacherByUserName(String userName){
        List<Teacher> user = userDao.getTeacherByUserName(userName);
        if (CollectionUtils.isNotEmpty(user)){
            return user;
        }
        return null;
    }


    public void insertUser(User user){
        userDao.insertUser(user);
    }
    public void insertUser(Student user){
        userDao.insertUser(user);
    }
    public void insertUser(Teacher user){
        userDao.insertUser(user);
    }

    public User getUsername(User user){
        List<User> u = userDao.getUsername(user);
        if (CollectionUtils.isNotEmpty(u)){
            return u.get(0);
        }
        return null;
    }
    public Teacher getUsername(Teacher user){
        List<Teacher> u = userDao.getUsername(user);
        if (CollectionUtils.isNotEmpty(u)){
            return u.get(0);
        }
        return null;
    }
    public Student getUsername(Student user){
        List<Student> u = userDao.getUsername(user);
        if (CollectionUtils.isNotEmpty(u)){
            return u.get(0);
        }
        return null;
    }

    public List<User> getUserAll(){
        List<User> users = userDao.getUserAll();
        return users;
    }
    public List<Student> getStudentAll(){
        List<Student> users = userDao.getStudentAll();
        return users;
    }
    public List<Teacher> getTeacherAll(){
        List<Teacher> users = userDao.getTeacherAll();
        return users;
    }

    public void delUserByUserName(String userName){
        userDao.delUserByUserName(userName);
    }
    public void delStudentByUserName(String userName){
        userDao.delStudentByUserName(userName);
    }
    public void delTeacherByUserName(String userName){
        userDao.delTeacherByUserName(userName);
    }

    public int updateUserByUserName(User user){
        int b = userDao.updateUserByUserName(user);
        return b;
    }
    public int updateStudentByUserName(Student user){
        int b = userDao.updateStudentByUserName(user);
        return b;
    }
    public int updateTeacherByUserName(Teacher user){
        int b = userDao.updateTeacherByUserName(user);
        return b;
    }
    //查询所有教师
    public List<Teacher> getAllTeacher(){
        List<Teacher> teacher = userDao.getAllTeacher();
        return teacher;
    }
    public List<User> getIdByUserName(String userName){
        return userDao.getIdByUserName(userName);
    }
    public List<Student> getNotChoiceTeacherStudent(){
        List<Student> unamelist = userDao.getNotChoiceTeacherStudent();
        return unamelist;
    }
    public List<Student> getStudentById(Long id){
        List<Student> student=userDao.getStudentById(id);
        return student;
    }

}
